home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / gnuemac_dev1_1.lha / autodocs.el next >
Lisp/Scheme  |  1993-01-06  |  5KB  |  136 lines

  1. ; Autodocs.el, by Cedric BEUST (beust@sa.inria.fr)
  2. ;    V1.3, Jan 7th 1992
  3. ;    Consult an autodoc function from emacs (18.58, Amiga port 1.26DG)
  4. ;    Main entry point : autodoc-show-autodoc (assigned to F2)
  5. ;
  6. ; The function is searched in the file *xref-file* somewhere in the Amigaguide
  7. ; path (setenv Amigaguide/path "path1 path2 path3..."). If you don't have AD2HT
  8. ; you can generate a compatible file that must have two words by line : the
  9. ; function name and its library, like :
  10. ;    "AllocAbs()"            "exec"        
  11. ;    "AllocAslRequest()"        "asl"        
  12. ; First, an Amigaguide file is searched through the Amigaguide path and displayed
  13. ; in Emacs' public screen (see the variable *emacs-public-screen*). If no
  14. ; Amigaguide file could be found, the autodocs are searched in the directory
  15. ; *autodocs-directory* (NB : the new V39 format is assumed, i.e. every file at
  16. ; the same level, no more "LibrariesA-K/", "LibrariesL-Z/", etc....) and the
  17. ; corresponding file is loaded and shown at the right place (see
  18. ; *autodoc-function-re*)
  19. ;
  20. ; All functions implemented here are prefixed by autodoc-
  21. ;
  22. ; OBSCURE FEATURES :
  23. ;
  24. ; KNOWN BUGS :
  25. ;
  26. ; IMPROVEMENTS SINCE PREVIOUS VERSION :
  27. ;   o can identify a word correctly even if it contains an _ or if the cursor
  28. ;     is on the first or last character
  29. ;   o use read shell-commands instead of Arexx hack (I needed a more recent
  30. ;     fifo-handler)
  31.  
  32.  
  33. ; Variables used here
  34.  
  35. ; The cross-reference file, that must be somewhere in the Amigaguide path
  36. (defvar *xref-file* "Autodocs.XRef")
  37.  
  38. ; Name of Emacs' public screen
  39. (defvar *emacs-public-screen* "EMACS")
  40.  
  41. ; Where to find the #?.doc
  42. (defvar *autodocs-directory* "Autodocs:")
  43.  
  44. ; Regular expression to find the definition of a function
  45. (defvar *autodoc-function-re* "^ .+library/")
  46.  
  47. ; Assign the main function to F2
  48.  
  49. (global-set-key "\C-x\C-^K" (make-sparse-keymap))
  50. (global-set-key "\C-x\C-^1~" 'autodoc-show-autodoc)
  51.  
  52. (defun autodoc-word-under-cursor ()
  53.   "Return the word under the cursor."
  54.   (let ((m1 0) (validchars "[a-zA-Z0-9_]"))
  55.     (save-excursion
  56.       (while (and (looking-at validchars)
  57.           (not (= (point-min) (point))))
  58.     (backward-char 1))
  59.       (setq m1 (point))
  60.       (while (and (looking-at validchars)
  61.           (not (= (point-max) (point))))
  62.     (forward-char 1))
  63.       (buffer-substring m1 (point)))))
  64.  
  65. (defun autodoc-exists-amigaguide-file (file)
  66.   "If the given file exists in the Amigaguide path, return its full path
  67.    else return nil"
  68.   (let ((paths (getenv "Amigaguide/path"))
  69.     (c 0)
  70.     (blank-pos 0)
  71.     (path ""))
  72.     (catch 'EXIT
  73.       (save-window-excursion
  74.     (while (and (> (length paths) 0)
  75.             (setq blank-pos (string-match " " paths)))
  76.       (setq path (substring paths 0 blank-pos))
  77.       (setq paths (substring paths (1+ blank-pos)))
  78.       (if (not (string-match "[:/]" (substring path (1- (length path)))))
  79.           (setq path (concat path "/")))
  80.       (if (file-readable-p (concat path file))
  81.           (throw 'EXIT (concat path file)))
  82.     ) ; outter while
  83.       ) ; save
  84.     ) ; catch
  85.   ) ; let
  86. ) ; defun
  87.  
  88.  
  89. (defun autodoc-shell-command (command)
  90.   "Launch the specified command"
  91.   (save-window-excursion
  92.     (shell-command command)))
  93.  
  94. (defun autodoc-show-amigaguide-file (file function)
  95. ;;  (print-debug (concat "Amigaguide Screen=EMACS Doc=" function "() " file))
  96. ;;  (print-debug (concat " showing " file " " function))
  97.   (autodoc-shell-command (concat "run >NIL: Amigaguide Screen="
  98.                  *emacs-public-screen*
  99.                  " Doc=" function "() " file)))
  100.  
  101. (defun autodoc-show-autodoc ()
  102.   "Show autodoc for the function under the cursor. First check if an Amigaguide
  103.    file is available, else display it in another emacs buffer."
  104.   (interactive)
  105.   (let* ((xref (autodoc-exists-amigaguide-file *xref-file*))
  106.      (m1 0)
  107.      (function (autodoc-word-under-cursor))
  108.      (guide-file "")
  109.      (command (concat "search " xref " " function))
  110.     )
  111.  
  112.     (if (not xref) (progn
  113.              (message (concat "Couldn't open the file " *xref-file*)))
  114.       (autodoc-shell-command command)
  115.       (message (concat "Looking for " function))
  116.       (save-window-excursion
  117.     (switch-to-buffer "*Shell Command Output*")
  118.     (beginning-of-buffer)
  119.     (search-forward (concat "\"" function))
  120.     (beginning-of-line)
  121.     (search-forward "\"" (point-max) t 3)
  122.     (setq m1 (point))
  123.     (search-forward "\"")
  124.     (setq guide-file (buffer-substring m1 (1- (point)))))
  125.  
  126.       (if (autodoc-exists-amigaguide-file guide-file)
  127.       (autodoc-show-amigaguide-file guide-file function)
  128.     (find-file (concat *autodocs-directory* guide-file ".doc"))
  129.     (switch-to-buffer (concat guide-file ".doc"))
  130.     (re-search-forward (concat *autodoc-function-re* function))
  131.     (next-line 1))
  132.     )
  133.   )
  134. )
  135.  
  136.